#!/usr/bin/python
from django.shortcuts import render
from core.forms.registration import RegistrationForm
from core.forms.login import AuthenticationForm
from core.models.subject import Subject
from chtozadali.core.models.task import UserTask
from chtozadali.core.views.utilits import get_subjects, sort_tasks

def get_main(request):
    if request.user.is_authenticated():
        tl = sort_tasks(list(UserTask.objects.filter(user__id=request.user.id, is_done=False)))
        tl = list(map(lambda x: x.task, tl))
        return render(request, 'feed.html', {"task_list": tl,
                                             "subjects": get_subjects(Subject.objects.all())})
    else:
        form = AuthenticationForm()
        return render(request, "login.html", {"form_auth": form})

    
